import tensorflow as tf

file_queue = tf.train.string_input_producer(
    tf.train.match_filenames_once("./random_ids*.tfrecords"))

reader = tf.TFRecordReader()
_, ser_sample = reader.read(file_queue)
batch_example = tf.train.shuffle_batch([ser_sample],
                  batch_size=32, num_threads=2,
                  capacity=100,
                  min_after_dequeue=40,
                  allow_smaller_final_batch=False
                  )

batch_tensor = tf.parse_example(batch_example, features = {
    'index': tf.FixedLenFeature([1], tf.int64),
    "ids": tf.VarLenFeature(tf.int64)})

sv = tf.train.Supervisor(logdir="./log")
with sv.managed_session() as sess:
    sv.start_queue_runners(sess)
    for _ in range(0, 8):
        if sv.should_stop():
            print("Supervisor break")
            break
        ids = sess.run(batch_tensor)
        print("ids = %r" % ids)
    
